<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取元素位置和大小</title>
    <style>
        .container
        {
            display: flex;
        }

        .box
        {
            width: 500px;
            height: 300px;
            background-color: orange;
            margin-right: 20px;
        }
       
        .btn
        {
            
            height: 40px;
            position: fixed;
            bottom: 0px;
            right: 20px;
        }

    </style>
</head>
<body>

    <div class="container">
         <div class="box"></div>
         <button class="btn">回到顶部</button>
    </div>

    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>

    <script>

        var btnEl = document.querySelector(".btn");
        btnEl.onclick = function()
        {
            scrollTo(0,0);
        }

    </script>
    
</body>
</html>